﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;

namespace SpriteExtractor.View
{
    /// <summary>
    /// Interaction logic for ImageMarkerView.xaml
    /// </summary>
    public partial class ImageMarker : Canvas
    {
        public ImageMarker()
        {
            InitializeComponent();

            //TODO temp solution
            image.SizeChanged += new SizeChangedEventHandler(image_SizeChanged);
        }

        void image_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            imageContainer.Width = e.NewSize.Width;
            imageContainer.Height = e.NewSize.Height;

            var imageViewModel = this.DataContext as ViewModel.ImageViewModel;
            imageViewModel.Size = e.NewSize;
        }

        private void imageContainer_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            var imageViewModel = this.DataContext as ViewModel.ImageViewModel;
            imageViewModel.Scale = imageViewModel.Scale + e.Delta;
            //TODO ImageViewModel should change the size of the image 
        }




        public Sprite ActiveSprite
        {
            get { return (Sprite)GetValue(ActiveSpriteProperty); }
            set { SetValue(ActiveSpriteProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ActiveSpriteProperty.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ActiveSpriteProperty =
            DependencyProperty.Register("ActiveSprite", typeof(Sprite), typeof(ImageMarker), new UIPropertyMetadata());

        private void sprite_MouseEnter(object sender, MouseEventArgs e)
        {
            this.ActiveSprite = e.OriginalSource as Sprite;
        }

        private void sprite_MouseLeave(object sender, MouseEventArgs e)
        {
            this.ActiveSprite = null;
        }

        
        
    }
}
